//
//  RTMainViewController.swift
//  Weibo
//
//  Created by Brisinga on 16/3/2.
//  Copyright © 2016年 Root. All rights reserved.
//

import UIKit

class RTMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // init
        setupUI()
    }

    
    // 初始化子控制器
    private func setupUI() {
        
        addChildViewController(RTHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        
        addChildViewController(RTMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        
        addChildViewController(RTDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        
        addChildViewController(RTPofileTableViewController(), imageName: "tabbar_profile", title: "我")
        
        
        // 设置tabbar
        let tabBar = RTTabBar()
        
        tabBar.composeButtonClickClosure = {[weak self] in
        
            print("hahaa\(self)")
            
            let composeView = RTComposeView()
            
            composeView.show(self!)
            
        }
        
        setValue(tabBar, forKeyPath: "tabBar")
        
        
        
    }
    
    
    private func addChildViewController(childController: UIViewController,imageName: String,title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: .Normal)
        
        childController.tabBarItem.titlePositionAdjustment.vertical = -3
        
        childController.title = title
        
        addChildViewController(RTNavgationController(rootViewController: childController))
    }
  

}
